package com.yonyou.brigade.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.service.IUserCenterService;
import com.yonyou.brigade.service.IBrigadePublicService;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/pushApplyOrder")
public class BrigadePublicController {
    @Autowired
    @Qualifier("brigadePublicServiceImpl")
    private IBrigadePublicService brigadePublicService;
    @Autowired
    @Qualifier("userCenterServiceImpl")
    private IUserCenterService iUserCenterService;

    /**
     * 申请单传给友商旅
     *
     * @return
     */
    @RequestMapping("/4rtpnr")
    public String pushApplyOrder4rtpnr() {
        String tenant = "a7exr9xj";
        String org_pk = "de2a72e4541f4cd3b72809d077288161";
        JSONObject pushTravelApplyOrder = new JSONObject();
        //飞机行程信息
        JSONArray FlightTrips = new JSONArray();
        JSONObject flight = new JSONObject();
        flight.put("IsDomc", "D");
        FlightTrips.add(flight);
        pushTravelApplyOrder.put("FlightTrips", FlightTrips);
        //
        pushTravelApplyOrder.put("TravelCode", "01");
        //酒店信息
        JSONArray hotelTrips = new JSONArray();
        JSONObject hotel = new JSONObject();
        hotel.put("IsDomc", "D");
        hotelTrips.add(hotel);
        pushTravelApplyOrder.put("HotelTrips", hotelTrips);

        pushTravelApplyOrder.put("Matters", "传友商旅");
        pushTravelApplyOrder.put("EndDate", "2018-11-20 00:00:00");
        pushTravelApplyOrder.put("StartDate", "2018-11-20 00:00:00");
        pushTravelApplyOrder.put("CreateStaffNum", "7c07c68a-1ab5-4207-ae12-0cf1b1cd68ab");
        pushTravelApplyOrder.put("ApproveType", "0");
        //出行人信息
        JSONArray travellers = new JSONArray();
        JSONObject traveller = new JSONObject();
        traveller.put("StaffNum", "7c07c68a-1ab5-4207-ae12-0cf1b1cd68ab");
        traveller.put("TrafficCode", "JP,HC,QC,QT");
        travellers.add(traveller);
        pushTravelApplyOrder.put("Travelers", travellers);
        //火车票信息
        JSONArray trainTrips = new JSONArray();
        JSONObject train = new JSONObject();
        train.put("IsDomc", "D");
        trainTrips.add(train);
        pushTravelApplyOrder.put("TrainTrips", trainTrips);

        pushTravelApplyOrder.put("IsRental", "1");
        pushTravelApplyOrder.put("IsValidateTrip", "N");
        pushTravelApplyOrder.put("OutOrderNo", "jbSC4YKWnYlvNVHylrog5");

        String result = brigadePublicService.pushTravelApplyOrder(tenant, org_pk, "rtpnr", pushTravelApplyOrder);
        return result;
    }

    /**
     * 测试查询火车票
     *
     * @return
     */
    @RequestMapping("/getTrainOrders")
    public Map getTrainOrders(@RequestBody Map param) {
        Map briTrainTicketDTOList = brigadePublicService.getBriTrainTicketDTOList(param);
        return briTrainTicketDTOList;
    }

    @RequestMapping("/fanscarApplayOrder")
    @ResponseBody
    public Object testFanscar(@RequestBody JSONObject param) {
        String tenant = "zrez2bx9";
        String org = "92599123b4ee4780ae0392e46e13d21e";
        return brigadePublicService.pushTravelApplyOrder(tenant, org, "", param);
    }

    @RequestMapping("/pushApplyOrder")
    @ResponseBody
    public Object pushApplyOrder(@RequestBody JSONObject params) {
        String tenant = params.getString("tenant");
        String org = params.getString("org");
        String channel = params.getString("channel");
        JSONObject applyInfo = params.getJSONObject("applyInfo");
        return brigadePublicService.pushTravelApplyOrder(tenant, org, channel, applyInfo);
    }


    @RequestMapping("/testconnect")
    @ResponseBody
    public Object testConnect(String phone, String tenant) {
        UcUserDto ucUserDto = iUserCenterService.getCompleteUcUserDtoByPhone(phone, tenant);
        return ucUserDto;
    }

    /**
     * 批量更新中兴已同步过的用户
     *
     * @param param
     * @return
     */
    @RequestMapping("/syncEmployees4Zteitc")
    @ResponseBody
    public String syncEmployees4Zteitc(@RequestBody JSONObject param) {
        return brigadePublicService.syncEmployees4Zteitc(param);
    }

}
